package day_2022_12_to_3.year2023;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2023/01/17 15:46
 **/
public class Day1_17_Num1814 {
    class Solution {
        public int countNicePairs(int[] nums) {
            if (nums.length <= 1) return 0;
            int ans = 0;
            Map<Integer, Integer> map = new HashMap<>();
            for (int i=0; i<nums.length; i++) {
                int tmp = nums[i], revNum = 0;
                while (tmp > 0) {
                    revNum = (revNum * 10) + (tmp % 10);
                    tmp /= 10;
                }
                int diff = nums[i] - revNum;
                int count = map.getOrDefault(diff, 0);
                ans = (ans + count) % 1000000007;
                map.put(diff, count +1);
            }
            return ans;
        }
    }
}